﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Data.SqlClient;
using System.Collections.Generic;
using Library;

namespace BusinessLayer
{
   public class Order_Detail
    {
        #region "Variables and Properties"
        //Variate 
        private int Order_Id;
        private string Product_Id;
        private int Quality;
        private int Status;
        // Property
        public int Order_Id1
        {
            get { return Order_Id; }
            set { Order_Id = value; }
        }

        public string Product_Id1
        {
            get { return Product_Id; }
            set { Product_Id = value; }
        }
        public int Quality1
        {
            get { return Quality; }
            set { Quality = value; }
        }
        public int Status1
        {
            get { return Status; }
            set { Status = value; }
        }

        #endregion

        #region "Initial Methods"
        public Order_Detail() { }
        public Order_Detail(SqlDataReader sdr)
        {
            if (sdr != null & !sdr.IsClosed)
            {
                Order_Id = sdr.GetInt32(0);
                if (sdr.IsDBNull(1))
                    Product_Id = sdr.GetString(1);
                if (sdr.IsDBNull(2))
                    Quality = sdr.GetInt32(2);
                if (sdr.IsDBNull(3))
                    Status = sdr.GetInt32(3);

            }
        }
        #endregion


        #region "Business Methods"
        //Get all Order_Detail
        public static List<Order_Detail> GetAll()
        {
            DBHelp dbh = new DBHelp();
            string cmd = "tbl_Order_Detail_SHOWALL";
            List<Order_Detail> lstOrder_Detail = new List<Order_Detail>();
            SqlDataReader sdr = dbh.ExecuteReader(cmd, CommandType.StoredProcedure);
            while (sdr.Read())
            {
                lstOrder_Detail.Add(new Order_Detail(sdr));
            }
            return lstOrder_Detail;
        }
        //Get one Order_Detail
        public static Order_Detail GetOne(int id)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Order_ID", id);
            string cmd = "tbl_Order_Detail_SHOWONE";
            Order_Detail order_detail = new Order_Detail();
            SqlDataReader sdr = dbh.ExecuteReader(cmd, CommandType.StoredProcedure);
            if (sdr.Read())
            {
                order_detail.Order_Id = sdr.GetInt32(0);
                if (!sdr.IsDBNull(1))
                    order_detail.Product_Id = sdr.GetString(1);
                if (!sdr.IsDBNull(2))
                    order_detail.Quality = sdr.GetInt32(2);
                if (!sdr.IsDBNull(3))
                    order_detail.Status = sdr.GetInt32(3);

            }
            return order_detail;
        }
        //Insert a Order_Detail
        public static void Insert(Order_Detail order_detail)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Quality", order_detail.Quality);
            string cmd = "tbl_Order_Detail_INSERT";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }
        //Update a Order_Detail
        public static void Update(Order_Detail order_detail)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Order_Id", order_detail.Order_Id);
            dbh.AddParameter("@Product_Id", order_detail.Product_Id);
            dbh.AddParameter("@Quality", order_detail.Quality);
            string cmd = "tbl_Order_Detail_UPDATE";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }
        //Delete a Order_Detail
        public static void Delete(int Id)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Order_ID", Id);
            string cmd = "tbl_Order_Detail_DELETE";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }
        #endregion
    }
}
